package com.hpe.fastfood.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hpe.fastfood.mapper.OrderMapper;
import com.hpe.fastfood.service.OrderService;
import com.hpe.fastfood.util.Page;
import com.hpe.fastfood.vo.OrderVo;

@Service
public class OrderServiceImpl implements OrderService {

	@Autowired
	private OrderMapper orderMapper;

	@Override
	public Page selectOrder(Page page) throws RuntimeException {
		// TODO Auto-generated method stub
		int start = (page.getCurPage() - 1) * page.getPageNumber();// 起始页
		List<OrderVo> stuClasses = orderMapper.selectOrder(start, page.getPageNumber());// 分页查询记录
		// 查询一共多少条记录
		int rows = orderMapper.selectCount();
		// 计算一共多少页
		int totalPage = rows % page.getPageNumber() == 0 ? rows / page.getPageNumber()
				: rows / page.getPageNumber() + 1;
		// 封装数据到page进行放回
		page.setDate(stuClasses);
		page.setRows(rows);
		page.setTotalPage(totalPage);
		return page;
	}

	@Override
	public List<OrderVo> selectOrderById(int foodId) throws RuntimeException {
		// TODO Auto-generated method stub
		return orderMapper.selectOrderById(foodId);
	}

	@Override
	public int selectCountById(int foodId) throws RuntimeException {
		// TODO Auto-generated method stub
		return orderMapper.selectCountById(foodId);
	}

	@Override
	public int sumFoodCountById(int foodId) throws RuntimeException {
		// TODO Auto-generated method stub
		return orderMapper.sumFoodCountById(foodId);
	}
}
